global:
  http_config:
    tls_config:
      insecure_skip_verify: true
  smtp_smarthost: '{{ alertmanager_arg.smtp_smarthost }}'
  smtp_from: '{{ alertmanager_arg.smtp_from }}'
  smtp_require_tls: {{ alertmanager_arg.smtp_require_tls | bool | to_json }}
  smtp_auth_username: '{{ alertmanager_arg.smtp_auth_username }}'
  smtp_auth_password: '{{ alertmanager_arg.smtp_auth_password }}'
  wechat_api_url: '{{ alertmanager_arg.wechat_api_url }}'

templates:
- '/etc/prometheus/templates/default.tmpl'

# https://prometheus.io/webtools/alerting/routing-tree-editor

route:
  group_by: ['{{ alertmanager_arg.group_by | list | join("', '") }}']
  group_wait: '{{ alertmanager_arg.group_wait }}'
  group_interval: '{{ alertmanager_arg.group_interval }}'
  repeat_interval: '{{ alertmanager_arg.repeat_interval }}'
  receiver: team-infra-mails
  routes:
{% if alertmanager_arg.wechat_api_corpid is defined %}
    - match:
        severity: {{ vars['prometheus_alert_incident_' + prometheus_alert_incident_levels_map].critical }}
      receiver: team-infra-wechat
      continue: true
    - match:
        severity: {{ vars['prometheus_alert_incident_' + prometheus_alert_incident_levels_map].high }}
      receiver: team-infra-wechat
      continue: true
{% endif %}
{% if alertmanager_arg.webhook_url is defined %}
    - match:
      receiver: team-infra-alerta
      continue: true
{% endif %}

inhibit_rules:
- source_match:
    severity: '{{ vars['prometheus_alert_incident_' + prometheus_alert_incident_levels_map].critical }}'
  target_match:
    severity: '{{ vars['prometheus_alert_incident_' + prometheus_alert_incident_levels_map].high }}'
  equal: ['{{ alertmanager_arg.group_by | list | join("', '") }}']

receivers:
  - name: 'team-infra-mails'
    email_configs:
      - send_resolved: true
        to: '{{ alertmanager_arg.mail_to_user }}'
{% if alertmanager_arg.wechat_api_corpid is defined %}
  - name: "team-infra-wechat"
    wechat_configs:
      - send_resolved: true
        to_party: '{{ alertmanager_arg.wechat_to_party }}'
        agent_id: '{{ alertmanager_arg.wechat_api_agentid }}'
        corp_id: '{{ alertmanager_arg.wechat_api_corpid }}'
        api_secret: '{{ alertmanager_arg.wechat_api_secret }}'
{% endif %}
{% if alertmanager_arg.webhook_url is defined %}
  - name: "team-infra-alerta"
    webhook_configs:
      - send_resolved: true
        url: '{{ alertmanager_arg.webhook_url }}'
{% endif %}
